package com.bang.sgg.controller;

import com.bang.sgg.EsRepostory;
import com.bang.sgg.persist.model.AgentSeat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Iterator;

/**
 * @Auther: Bang
 * @Date: 2019/11/24 20:29
 * @Description:
 */
@RestController
public class ElasticsearchController {

    @Autowired
    private EsRepostory esRepostory;

    @GetMapping("/index")
    public Object index() {
        AgentSeat agentSeat = new AgentSeat();
        agentSeat.setId(2L);
        agentSeat.setExtCode("10086");
        agentSeat.setSeatCode("bang");
        agentSeat.setExtPass("123456");
        AgentSeat seat = esRepostory.index(agentSeat);
        return seat;
    }

    @GetMapping("/query")
    public void query() {
        Iterable<AgentSeat> all = esRepostory.findAll();
        Iterator<AgentSeat> iterator = all.iterator();
        while (iterator.hasNext()) {
            AgentSeat next = iterator.next();
            System.err.println(next);
        }
    }
}
